package com.tianya.common.taglib;

import java.io.*;
import java.util.Map;

import javax.servlet.jsp.*;
import com.tianya.common.util.CodeUtils;

import org.apache.commons.lang.StringUtils;

public class WriteCodeLabelTag extends
		javax.servlet.jsp.tagext.SimpleTagSupport {

	private String displayField;


	private String code;
	private String id;
	private String lang;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDisplayField() {
		return displayField;
	}

	public void setDisplayField(String displayField) {
		this.displayField = displayField;
	}
	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}
	
	@SuppressWarnings("unchecked")
	public void doTag() throws JspException, IOException {
		Map oCode;
		oCode = CodeUtils.GetCode((PageContext) this.getJspContext(),
				this.code, this.id,this.lang);
		if (oCode == null) {
			this.getJspContext().getOut().write("");
			return;
		}

		if (StringUtils.isEmpty(displayField)) {
			displayField = "NAME";
		}
		this.getJspContext().getOut().write(
				String.valueOf(oCode.get(displayField)));

	}


}
